<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-input v-model="queryParams.proNo" placeholder="请输入物品编号" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['wms:supervise:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['wms:supervise:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['wms:supervise:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['wms:supervise:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="superviseList" @selection-change="handleSelectionChange" border stripe>
      <el-table-column type="index" width="55" align="center" />
      <!-- <el-table-column label="主键" align="center" prop="id" v-if="true" /> -->
      <el-table-column label="物品编号" align="center" prop="proNo" min-width="160"/>
      <el-table-column label="监督信息" align="center" prop="superviseMessage" />
      <el-table-column label="监督单位" align="center" prop="superviseUnit" />
      <el-table-column label="监督人" align="center" prop="supervisor" />
      <el-table-column label="接收单位" align="center" prop="receiveUnit" />
      <!-- <el-table-column label="${comment}" align="center" prop="migStat" /> -->
      <!-- <el-table-column label="是否审核" align="center" prop="isCheck" /> -->

      <el-table-column label="回复信息" align="center" prop="backMessage" />
      <el-table-column label="回复人" align="center" prop="backer" />
      <el-table-column label="回复时间" align="center" prop="backTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.backTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
       <template slot-scope="scope">
         <dict-tag :options="dict.type.wms_supervise_status" :value="scope.row.status" />
       </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['wms:supervise:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['wms:supervise:remove']">删除</el-button> -->
            <el-button v-if="scope.row.status == '0'" size="mini" type="text" icon="el-icon-edit" @click="handleInfo(scope.row)"
              v-hasPermi="['wms:supervise:edit']">回复</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改监督反馈对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="880px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="编号" prop="proNo">
              <el-input v-model="form.proNo" placeholder="请输入编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="监督信息" prop="superviseMessage">
              <el-input v-model="form.superviseMessage" placeholder="请输入监督信息" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="监督单位" prop="superviseUnit">
              <el-input v-model="form.superviseUnit" placeholder="请输入监督单位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15"><el-col :span="8">
            <el-form-item label="监督人" prop="supervisor">
              <el-input v-model="form.supervisor" placeholder="请输入监督人" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="接收单位" prop="receiveUnit">
              <el-input v-model="form.receiveUnit" placeholder="请输入接收单位" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="${comment}" prop="migStat">
              <el-input v-model="form.migStat" placeholder="请输入${comment}" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15"><el-col :span="8">
            <el-form-item label="是否审核" prop="isCheck">
              <el-input v-model="form.isCheck" placeholder="请输入是否审核" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="财物编号" prop="wpbh">
              <el-input v-model="form.wpbh" placeholder="请输入财物编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="回复信息" prop="backMessage">
              <el-input v-model="form.backMessage" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15"><el-col :span="8">
            <el-form-item label="回复人" prop="backer">
              <el-input v-model="form.backer" placeholder="请输入回复人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="回复时间" prop="backTime">
              <el-date-picker clearable size="small" v-model="form.backTime" type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择回复时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-drawer :visible.sync="info"  :before-close="handleClose" size="60vw">
      <div class="mainDiv">
        <el-container class="main_container">
          <el-main>
            <el-descriptions class="margin-top" :title="title" :column="3" border>
                <el-descriptions-item label="编号">{{form.proNo}}</el-descriptions-item>
                <el-descriptions-item label="财物编号" span="2">{{form.wpbh}}</el-descriptions-item>
                <el-descriptions-item label="监督单位">{{form.superviseUnit}}</el-descriptions-item>
                <el-descriptions-item label="监督人">{{form.supervisor}}</el-descriptions-item>
                <el-descriptions-item label="接收单位" :span="2">{{form.receiveUnit}}</el-descriptions-item>
                <el-descriptions-item label="监督信息" :span="3">{{form.superviseMessage}}</el-descriptions-item>
            </el-descriptions>
            <el-card class="mt20" shadow="never">
              <div slot="header" class="clearfix">
                <span>回复</span>
              </div>
              <el-form ref="form" :model="form" :rules="rules" >
                <el-form-item prop="backMessage">
                  <el-input type="textarea" v-model="form.backMessage" placeholder="请输入..."></el-input>
                </el-form-item>
              </el-form>
            </el-card>
          </el-main>
          <el-footer class="footerDivClass">
            <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </el-footer>
        </el-container>
      </div>
    </el-drawer>
  </div>
</template>

<script>
  import {
    listSupervise,
    getSupervise,
    delSupervise,
    addSupervise,
    updateSupervise
  } from "@/api/wms/supervise";
  export default {
    name: "Supervise",
    dicts:['wms_supervise_status'],
    data() {
      return {
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 监督反馈表格数据
        superviseList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          backMessage: [{
            required: true,
            message: "回复信息不能为空",
            trigger: "blur"
          }],
        },

        info:false
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询监督反馈列表 */
      getList() {
        this.loading = true;
        listSupervise(this.queryParams).then(response => {
          this.superviseList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.info = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          proNo: undefined,
          superviseMessage: undefined,
          superviseUnit: undefined,
          supervisor: undefined,
          receiveUnit: undefined,
          migStat: undefined,
          isCheck: undefined,
          wpbh: undefined,
          createBy: undefined,
          createTime: undefined,
          updateBy: undefined,
          updateTime: undefined,
          delFlag: undefined,
          backMessage: undefined,
          backer: undefined,
          backTime: undefined,
          status: "0"
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加监督反馈";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.loading = true;
        this.reset();
        const id = row.id || this.ids
        getSupervise(id).then(response => {
          this.loading = false;
          this.form = response.data;
          this.open = true;
          this.title = "修改监督反馈";
        });
      },

      handleInfo(row){
        this.loading = true;
        const id = row.id || this.ids
        getSupervise(id).then(response => {
          this.loading = false;
          this.form = response.data;
          this.info = true;
          this.title = "反馈";
        });
      },
      handleClose(){
        this.info = false;
      },

      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.form.id != null) {
              updateSupervise(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.info = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addSupervise(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.info = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除监督反馈编号为"' + ids + '"的数据项？').then(() => {
          this.loading = true;
          return delSupervise(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).finally(() => {
          this.loading = false;
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('wms/supervise/export', {
          ...this.queryParams
        }, `supervise_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
